Crate socketpair[][src]

Cross-platform socketpair functionality

A socketpair stream is a bidirectional bytestream. The socketpair_stream function creates a pair of SocketpairStream objects connected to opposite ends of a stream, and both can be written to and read from.

use socketpair::socketpair_stream;
use std::{
    io::{self, Read, Write},
    thread,
};

fn main() -> anyhow::Result<()> {
    let (mut a, mut b) = socketpair_stream()?;

    let _t = thread::spawn(move || -> io::Result<()> { writeln!(a, "hello world") });

    let mut buf = String::new();
    b.read_to_string(&mut buf)?;
    assert_eq!(buf, "hello world\n");

    Ok(())
}

Structs

SocketpairStream

A socketpair stream, which is a bidirectional bytestream much like a UnixStream except that it does not have a name or address.

Functions

socketpair_stream

Create a socketpair and return stream handles connected to each end.